VBScript → Lua
This function checks if the current caller (i.e. his phone number) can be found in a given text file. It can be used to create black or white lists for incoming calls on a user.
Please see the Introduction chapter for some usage instructions.
' FileOpen iomode Values
Const fsoForReading = 1 ' Open a file for reading only.
Const fsoForWriting = 2 ' Open a file for writing only.
Const fsoForAppending = 8 ' Open a file and write to the end of the file.
Const fsoDontCreateIfNotExist = False
Const fsoCreateIfNotExist = True
Const fsoTristateUseDefault = -2 ' Opens the file by using the system default.
Const fsoTristateTrue = -1 ' Opens the file as Unicode.
Const fsoTristateFalse = 0 ' Opens the file as ASCII.
'----------------------------------------------------------------
' CheckCallerInTextFile
'
' Returns true if the current callers phone number can be found in a given text file.
' The text file must be formatted with one number per line.
'
' Parameter:
' sFileName text file (incl. path) that contains the numbers to check
'
' Return:
' boolean
'----------------------------------------------------------------
Function CheckCallerInTextFile ( sFileName )
PBXScript.OutputTrace "-----------> CheckCallerInTextFile (" & sFileName & ")"
Dim bReturn, sCaller, sLine
bReturn = False
On Error Resume Next
sCaller = PBXCall.CallingPartyNumber
PBXScript.OutputTrace "sCaller = " & sCaller
Dim fso, file
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists( sFileName ) Then
Set file = fso.OpenTextFile(sFileName, fsoForReading, fsoDontCreateIfNotExist, fsoTristateFalse)
If Err = 0 Then
PBXScript.OutputTrace "File opened"
Do While (Not file.AtEndOfStream) And (Not bReturn)
sLine = file.ReadLine
PBXScript.OutputTrace "sLine = " & sLine
' does the number in the text file contain the given number?
If InStr(sLine, sCaller) > 0 Then
bReturn = True
PBXScript.OutputTrace "Found!"
End If
' does the number in the text file is identical to the given number?
'If sLine = sCaller Then
' bReturn = True
' PBXScript.OutputTrace "Found!"
'End If
Loop
file.Close
Else
PBXScript.OutputTrace "Error opening file!"
PBXScript.OutputTrace Hex(Err) & ": " & Err.Description
End If
Set file = Nothing
Else
PBXScript.OutputTrace "File does not exist!"
End If
Set fso = Nothing
CheckCallerInTextFile = bReturn
PBXScript.OutputTrace "bReturn = " & bReturn
PBXScript.OutputTrace "<----------- CheckCallerInTextFile"
End Function
This function makes use of the Server Script API functions PBXCall.CallingPartyNumber to get the callers number and PBXScript.OutputTrace to write trace information into the SwyxServer trace file.
You need to make sure, that the file can be accessed from the call routing script. For this it is necessary, that the Windows users the Swyx Server service is running under (usually SwyxServiceAccount) has at least read privileges on the file.
The function was originally posted into this forum topic.
By Tom Wellige
